import request from './request'
import type { LoginRequest, LoginResponse, User } from '@/types'

/**
 * 登录
 */
export function login(data: LoginRequest) {
  return request<LoginResponse>({
    url: '/auth/login/',
    method: 'post',
    data
  })
}

/**
 * 刷新 Token
 */
export function refreshToken(refresh: string) {
  return request<{ access: string }>({
    url: '/auth/refresh/',
    method: 'post',
    data: { refresh }
  })
}

/**
 * 获取当前用户信息
 */
export function getCurrentUser() {
  return request<User>({
    url: '/auth/me/',
    method: 'get'
  })
}

/**
 * 修改密码
 */
export interface ChangePasswordRequest {
  old_password: string
  new_password: string
}

export function changePassword(data: ChangePasswordRequest) {
  return request<{ message: string }>({
    url: '/auth/change-password/',
    method: 'post',
    data
  })
}

